DXL to parse a file

Can someone please point me in the right direction with a code snippet to parse a file.

I have a DXL script that creates a log file, which I need to search for occurrences of a specific string. The string can be hard coded; no need to prompt the user for input. Output will be nothing fancy just indicate in an infoBox how many (if any) occurrences there were.

Thanks in adavance,
Ken.
mcnairk - Mon Jul 06 11:29:34 EDT 2009

Re: DXL to parse a file
pete.kowalski - Mon Jul 06 22:24:59 EDT 2009

Hi Ken,

Are you able to post the format of this log file? If not then I will create a custom log file and show you how I parse that out.

Re: DXL to parse a file
pete.kowalski - Mon Jul 06 22:34:52 EDT 2009

pete.kowalski - Mon Jul 06 22:24:59 EDT 2009
Hi Ken,

Are you able to post the format of this log file? If not then I will create a custom log file and show you how I parse that out.

Here is a quick example I just thought of.
 

Stream inFile = read "D:\\log.txt"
string fooString 
 
Regexp myReg = regexp "[0-9]+"
 
while (true)
{
    inFile >> fooString
        if (end inFile)
        {
                infoBox "nothing else to read in file"
                break
        }
        
        if (matches(":",fooString))
        {
                if (myReg fooString)
                {
                        print fooString[match 0] "\n"
                }
        }
        
        
}
 
close(inFile)

 


The log.txt file is attached. Reply back if you need me to explain anything a bit more or have futher questions.

 


Attachments

attachment_14270918_log.txt

Re: DXL to parse a file
mcnairk - Tue Jul 07 10:43:47 EDT 2009

pete.kowalski - Mon Jul 06 22:34:52 EDT 2009

Here is a quick example I just thought of.
 

Stream inFile = read "D:\\log.txt"
string fooString 
 
Regexp myReg = regexp "[0-9]+"
 
while (true)
{
    inFile >> fooString
        if (end inFile)
        {
                infoBox "nothing else to read in file"
                break
        }
        
        if (matches(":",fooString))
        {
                if (myReg fooString)
                {
                        print fooString[match 0] "\n"
                }
        }
        
        
}
 
close(inFile)

 


The log.txt file is attached. Reply back if you need me to explain anything a bit more or have futher questions.

 

Thanks Pete! With a few tweaks I was able to get your code to work. It was the stream manipulation bit I wasn't sure of.

FYI, here is a sample my log file. This is produced by perm checkDataAgainstHistory_ (which is same as the administrator "check data against history" tool) so I don't have access to the actual code. Otherwise I would be counting the mismatches as I went along, instead of logging them to a file and the parsing the file afterwards for occurrences of string "mismatch".

Ken.
 

*******************************************************************************
History check on /My Project/My Module, begun 6/26/2009 07:23:20
 
- Not checking baselined history.
- Checking attribute values in Deleted objects.
 
******* Attribute value mismatch: Proposed Change *******
History entry details in current version:
modifyObject    Object: 17818   Session: 4254   User: mcnairk   Date: 3/12/2009 10:19:30
 
Summary of results:
1 Attribute values not matching values in history.
 
History check completed at 6/26/2009 07:23:33

Re: DXL to parse a file
senhu - Tue Jul 07 12:29:05 EDT 2009

Here is an alternate script. I will assume your log file is in C:\somefile.log .
  1. Script mismatch.txt
var str log ; cat "S:\somefile.log" > $log
sen "mismatch" $log
The above 2-liner will print the number of occurrences of string "mismatch". The script is in biterscripting ( Link: http://www.biterscripting.com ) .

Sen

Re: DXL to parse a file
senhu - Tue Jul 07 12:31:57 EDT 2009

That pervious post did not look alright. Here is the one that should look better.

Here is an alternate script. I will assume your log file is in C:\somefile.log .
 

# Script mismatch.txt
var str log ; cat "C:\somefile.log" > $log
sen "^mismatch^" $log


The above 2-liner will print the number of occurrences of string "mismatch". The script is in biterscripting ( Link: http://www.biterscripting.com ) .

Sen

Re: DXL to parse a file
pete.kowalski - Sat Jul 11 18:48:12 EDT 2009

mcnairk - Tue Jul 07 10:43:47 EDT 2009

Thanks Pete! With a few tweaks I was able to get your code to work. It was the stream manipulation bit I wasn't sure of.

FYI, here is a sample my log file. This is produced by perm checkDataAgainstHistory_ (which is same as the administrator "check data against history" tool) so I don't have access to the actual code. Otherwise I would be counting the mismatches as I went along, instead of logging them to a file and the parsing the file afterwards for occurrences of string "mismatch".

Ken.
 

*******************************************************************************
History check on /My Project/My Module, begun 6/26/2009 07:23:20
 
- Not checking baselined history.
- Checking attribute values in Deleted objects.
 
******* Attribute value mismatch: Proposed Change *******
History entry details in current version:
modifyObject    Object: 17818   Session: 4254   User: mcnairk   Date: 3/12/2009 10:19:30
 
Summary of results:
1 Attribute values not matching values in history.
 
History check completed at 6/26/2009 07:23:33

Ken,

Good to hear. With the sample log file what do you want parsed out? Just curious because the code I came up with was on the fly and naturally not optimized.

Re: DXL to parse a file
mcnairk - Mon Jul 13 08:18:14 EDT 2009

pete.kowalski - Sat Jul 11 18:48:12 EDT 2009
Ken,

Good to hear. With the sample log file what do you want parsed out? Just curious because the code I came up with was on the fly and naturally not optimized.

Here's my code:
 

Stream inFile = read Filename
string fooString
 
while (true)
{
    inFile >> fooString
        if (end inFile)
                {break}
        
        if (matches("mismatch",fooString))
                {count++}
}
        close(inFile)
 
if (count == 0)
        {infoBox "Output file:\n" Filename "\ncontains no history mismatches"}
else
        {
        if (file_exists == true) {warningBox "Output file:\n" Filename "\ncontains a total of " count " history mismatches\n\nFile was appended to; mismatch count may not be accurate"}
        else {warningBox "Output file:\n" Filename "\ncontains a total of " count " history mismatches"}
        }
}

 


Thanks,
Ken.

 

Re: DXL to parse a file
mcnairk - Mon Jul 13 14:52:26 EDT 2009

mcnairk - Mon Jul 13 08:18:14 EDT 2009

Here's my code:
 

Stream inFile = read Filename
string fooString
 
while (true)
{
    inFile >> fooString
        if (end inFile)
                {break}
        
        if (matches("mismatch",fooString))
                {count++}
}
        close(inFile)
 
if (count == 0)
        {infoBox "Output file:\n" Filename "\ncontains no history mismatches"}
else
        {
        if (file_exists == true) {warningBox "Output file:\n" Filename "\ncontains a total of " count " history mismatches\n\nFile was appended to; mismatch count may not be accurate"}
        else {warningBox "Output file:\n" Filename "\ncontains a total of " count " history mismatches"}
        }
}

 


Thanks,
Ken.

 

I discovered a logic error that a match detected in the last line in the file is not detected. The test for the end of the file needs to be moved after the match statement:
 

Stream inFile = read Filename
string fooString
 
while (true)
{
    inFile >> fooString
                
        if (matches("mismatch",fooString))
                {count++}
 
        if (end inFile)
                {break}
 
}
        close(inFile)
 
if (count == 0)
        {infoBox "Output file:\n" Filename "\ncontains no history mismatches"}
else
        {
        if (file_exists == true) {warningBox "Output file:\n" Filename "\ncontains a total of " count " history mismatches\n\nFile was appended to; mismatch count may not be accurate"}
        else {warningBox "Output file:\n" Filename "\ncontains a total of " count " history mismatches"}
        }
}

Re: DXL to parse a file
Bosch - Mon Oct 03 10:32:30 EDT 2011

mcnairk - Mon Jul 13 14:52:26 EDT 2009

I discovered a logic error that a match detected in the last line in the file is not detected. The test for the end of the file needs to be moved after the match statement:
 

Stream inFile = read Filename
string fooString
 
while (true)
{
    inFile >> fooString
                
        if (matches("mismatch",fooString))
                {count++}
 
        if (end inFile)
                {break}
 
}
        close(inFile)
 
if (count == 0)
        {infoBox "Output file:\n" Filename "\ncontains no history mismatches"}
else
        {
        if (file_exists == true) {warningBox "Output file:\n" Filename "\ncontains a total of " count " history mismatches\n\nFile was appended to; mismatch count may not be accurate"}
        else {warningBox "Output file:\n" Filename "\ncontains a total of " count " history mismatches"}
        }
}

Hello ,

Attached is the txt file which i want to parse it.

in the txt file I have the tags "#IssueStart#" and #IssueEnd#, within that i have some values ie.
if issuekey= somevalue then i have to create a new object at the last of the module.
I have to update the attributes to the newly created object with the values present in txt file like in the txt file i have a
Objectheading = #start#"xyz"#End#,i have to get the value between the two tags #start# and #end#.
similarly for other attributes.

I have to create an object for every "#IssueStart#" and #IssueEnd# in the txt file

Kindly help me..
Kindly let me know if any further details are required.

Thank you!

Regards,
Shruthi
Attachments

attachment_14689018_New_Text_Document.txt